package com.hp.team.bookstore.dbaccess.dao.profile;

import java.util.List;

import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.hp.team.bookstore.dbaccess.dao.GenericHibernateDAO;
import com.hp.team.bookstore.model.profile.User;

@Repository
public class UserHibernateDAO extends GenericHibernateDAO<User, Long> {

	@SuppressWarnings("unchecked")
	public List<User> findByRole(User exampleUser, String roleName) {

		Example example = getExample(exampleUser);

		return (List<User>) getSession()
				.createCriteria(User.class).add(example)
				.createCriteria("roles").add(Restrictions.like("name", roleName))
				.list();
	}

}
